package com.ydkj.a37e_mall.Classes.Acitivity.BaseActivity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.format.DateUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.baidu.navisdk.adapter.BNOuterLogUtil;
import com.baidu.navisdk.adapter.BNOuterTTSPlayerCallback;
import com.baidu.navisdk.adapter.BNRoutePlanNode;
import com.baidu.navisdk.adapter.BaiduNaviManager;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshGridView;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.ydkj.a37e_mall.Classes.Applicatiom.MyApplication;
import com.ydkj.a37e_mall.Classes.Model.Request.SearchInfo;
import com.ydkj.a37e_mall.Classes.Model.Request.SearchProductReq;
import com.ydkj.a37e_mall.Classes.Model.Request.SearchStoreReq;
import com.ydkj.a37e_mall.Classes.Model.Response.SearchProductResp;
import com.ydkj.a37e_mall.Classes.Model.Response.SearchStoreResp;
import com.ydkj.a37e_mall.R;
import com.ydkj.a37e_mall.Resource.Utils.Async_http_get;
import com.ydkj.a37e_mall.Resource.Utils.CommonUtil;
import com.ydkj.a37e_mall.Resource.Utils.Const;
import com.ydkj.a37e_mall.Resource.Utils.GsonImpl;
import com.ydkj.a37e_mall.Resource.Utils.Rsa;
import com.ydkj.a37e_mall.Resource.Utils.SharedPreferencesUtil;
import com.ydkj.a37e_mall.Resource.View.CustomProgressDialog;
import com.ydkj.a37e_mall.Resource.View.StatusBarUtil;
import com.ydkj.a37e_mall.Resource.View.WordWrapView;
import com.ydkj.a37e_mall.Resource.sql.DataHelper;

import org.json.JSONObject;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.onekeyshare.OnekeyShare;
import cz.msebera.android.httpclient.Header;

import static com.baidu.navisdk.adapter.PackageUtil.getSdcardDir;
import static com.ydkj.a37e_mall.R.id.img_search_product;


/**
 * Created by Administrator on 2017/1/7.
 * <p>
 * 搜索页面
 */

public class Search extends BaseActivity implements View.OnClickListener {
    private Activity mActivity;
    private SharedPreferencesUtil sharedPreferencesUtil;
    private MyApplication myApplication;
    private TextView tv_search_commodity, tv_search_store;
    private EditText et_search;
    private LinearLayout lly_search;
    private RelativeLayout rly_search, rly_gv_search, rly_lv_search, rly_classification;
    private WordWrapView hot_search_Layout; //热搜
    private WordWrapView history_search_Layout; //历史搜索
    private PullToRefreshListView lv_search_result;
    private PullToRefreshGridView gv_search_result;
    private SearchGridviewAdapter searchGridviewAdapter;
    //    private SearchListviewAdapter searchListviewAdapter;
    private List<SearchProductResp.ResultEntity.DataEntity> searchproductList;
    private DataHelper dataHelper;
    private List<SearchInfo> searchinfolist;
    private List<SearchStoreResp.ResultEntity.DataEntity> searchListviewlist;
    private PopupWindow pop_phone;
    private LinearLayout lly_pop_phone;
    private TextView tv_pop_phone, tv_pop_cancel;
    private String mSDCardPath = null;
    private static final String APP_FOLDER_NAME = "BNSDKDemo";
    public static final String ROUTE_PLAN_NODE = "routePlanNode";
    private String authinfo = null;
    private static final int LOAD = 0;// 加载
    private static final int REFRESH = 1;// 刷新
    private static final int MORE = 2;// 更多
    private int page;
    private int code = 0;//用来判断搜索商品还是店铺

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.search);
        mActivity = this;


//        BNOuterLogUtil.setLogSwitcher(true);//
//        if (initDirs()) {
//            Log.e("ssss", "initNavi");
//            initNavi();
//        }
        init();
        Getsearchproduct(REFRESH);
//        initWindow();
        init_hot_search();
        init_history_search();
    }

    private void initWindow() {
        StatusBarUtil.setColor(mActivity, getResources().getColor(R.color.A000000), 0);
    }

    private void init() {


        dataHelper = new DataHelper(mActivity);
        sharedPreferencesUtil = SharedPreferencesUtil.getInstance(mActivity);
        myApplication = MyApplication.getInstance();
        searchinfolist = new ArrayList<>();

        rly_classification = (RelativeLayout) mActivity.findViewById(R.id.rly_classification);
        rly_classification.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        tv_search_commodity = (TextView) mActivity.findViewById(R.id.tv_search_commodity);
        tv_search_commodity.setSelected(true);
        tv_search_store = (TextView) mActivity.findViewById(R.id.tv_search_store);
        lly_search = (LinearLayout) mActivity.findViewById(R.id.lly_search);
        rly_search = (RelativeLayout) mActivity.findViewById(R.id.rly_search);
        rly_gv_search = (RelativeLayout) mActivity.findViewById(R.id.rly_gv_search);
        rly_lv_search = (RelativeLayout) mActivity.findViewById(R.id.rly_lv_search);

        //搜索栏
        et_search = (EditText) mActivity.findViewById(R.id.et_search);

        initEditTextSearch();


        //门店
//        searchListviewlist = new ArrayList<>();
//        lv_search_result = (PullToRefreshListView) mActivity.findViewById(R.id.lv_search_result);
//        lv_search_result.setMode(PullToRefreshBase.Mode.BOTH);
//        searchListviewAdapter = new SearchListviewAdapter(searchListviewlist);
//        lv_search_result.setAdapter(searchListviewAdapter);
//        lv_search_result.setOnRefreshListener2(new PullToRefreshBase.OnRefreshListener2<ListView>() {
//            @Override
//            public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
//                GetsearchStore(REFRESH);
//            }
//
//            @Override
//            public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
//                GetsearchStore(MORE);
//            }
//        });


        //商品
        gv_search_result = (PullToRefreshGridView) mActivity.findViewById(R.id.gv_search_result);
        gv_search_result.setMode(PullToRefreshBase.Mode.BOTH);
        searchproductList = new ArrayList<>();
        searchGridviewAdapter = new SearchGridviewAdapter(searchproductList);
        gv_search_result.setAdapter(searchGridviewAdapter);
        gv_search_result.setOnRefreshListener2(new PullToRefreshBase.OnRefreshListener2<GridView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<GridView> refreshView) {
                String label = DateUtils.formatDateTime(mActivity.getApplicationContext(), System.currentTimeMillis(),
                        DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL);
                // Update the LastUpdatedLabel
                refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);
                Getsearchproduct(REFRESH);
            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<GridView> refreshView) {
                String label = DateUtils.formatDateTime(mActivity.getApplicationContext(), System.currentTimeMillis(),
                        DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL);
                // Update the LastUpdatedLabel
                refreshView.getLoadingLayoutProxy().setLastUpdatedLabel(label);
                // Do work to refresh the list here.
                Getsearchproduct(MORE);
            }
        });


        tv_search_commodity.setOnClickListener(this);
        tv_search_store.setOnClickListener(this);
        rly_search.setOnClickListener(this);
    }

    //搜索页面中键盘搜索键的监听
    private void initEditTextSearch() {
        et_search.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
                if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                    Log.e("ssss", "搜索");
                    SearchInfo searchinfo = new SearchInfo();
                    //将搜索记录添加到数据库中
                    searchinfo.setSearchname(et_search.getText().toString());
                    dataHelper.SaveVoiceInfo(searchinfo);
                    init_history_search();

                    if (code == 0) {
                        Getsearchproduct(LOAD);//搜索商品
                        lly_search.setVisibility(View.GONE);
                        rly_gv_search.setVisibility(View.VISIBLE);
                        rly_lv_search.setVisibility(View.GONE);
                    } else if (code == 1) {
                        Getsearchproduct(LOAD);//搜索门店
                        lly_search.setVisibility(View.GONE);
                        rly_gv_search.setVisibility(View.GONE);
                        rly_lv_search.setVisibility(View.VISIBLE);
                    }


                    return true;
                }

                return false;
            }
        });
    }

    //热门搜索
    private void init_hot_search() {
        hot_search_Layout = (WordWrapView) mActivity.findViewById(R.id.hot_search_Layout);

        final List<String> list = new ArrayList<>();
        list.add("123");
        list.add("iPhone");
        list.add("让他");
        list.add("请问");
        list.add("光和热非港行");
        list.add("拒绝");
        list.add("两节课了");
        list.add("有天赋与");
        list.add("个");


        for (int i = 0; i < list.size(); i++) {
            LinearLayout top1Layout = (LinearLayout) LayoutInflater.from(mActivity).inflate(R.layout.search_radiobutton, null);
            final TextView top1TextView = (TextView) top1Layout.findViewById(R.id.top_radiobutton);
            top1TextView.setText(list.get(i));
            hot_search_Layout.addView(top1Layout);
            final int postion = i;

            top1TextView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    String str = list.get(postion);
                    et_search.setText(str);
                    Getsearchproduct(LOAD);
                    Log.e("ssss", "热门搜索==》" + str);
                    lly_search.setVisibility(View.GONE);
                    rly_gv_search.setVisibility(View.VISIBLE);
                    rly_lv_search.setVisibility(View.GONE);
                }
            });
        }
    }

    //历史搜索
    private void init_history_search() {
        history_search_Layout = (WordWrapView) mActivity.findViewById(R.id.history_search_Layout);
        history_search_Layout.removeAllViews();
        searchinfolist = dataHelper.GetVoiceInfo();

        for (int i = 0; i < searchinfolist.size(); i++) {
            Log.e("ssss", "历史搜索==》" + searchinfolist.get(i).getSearchname());
            LinearLayout top1Layout = (LinearLayout) LayoutInflater.from(mActivity).inflate(R.layout.search_radiobutton, null);
            final TextView top1TextView = (TextView) top1Layout.findViewById(R.id.top_radiobutton);
            top1TextView.setText(searchinfolist.get(i).getSearchname());
            history_search_Layout.addView(top1Layout);
            final int postion = i;

            top1TextView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    String str = searchinfolist.get(postion).getSearchname();
                    et_search.setText(str);
                    Log.e("ssss", "历史搜索==》" + str);
                    Getsearchproduct(LOAD);
                    lly_search.setVisibility(View.GONE);
                    rly_gv_search.setVisibility(View.VISIBLE);
                    rly_lv_search.setVisibility(View.GONE);
                }
            });
        }
    }

    @Override
    public void onClick(View view) {

        switch (view.getId()) {
            case R.id.tv_search_commodity: //商品
                code = 0;
                tv_search_commodity.setSelected(true);
                tv_search_store.setSelected(false);
                if (et_search.getText().toString().equals("")) {
                    lly_search.setVisibility(View.VISIBLE);
                    rly_gv_search.setVisibility(View.GONE);
                    rly_lv_search.setVisibility(View.GONE);
                } else {
                    lly_search.setVisibility(View.GONE);
                    rly_gv_search.setVisibility(View.VISIBLE);
                    rly_lv_search.setVisibility(View.GONE);
                }
                searchGridviewAdapter.notifyDataSetChanged();
                break;
            case R.id.tv_search_store://门店
                code = 1;
                tv_search_commodity.setSelected(false);
                tv_search_store.setSelected(true);
                lly_search.setVisibility(View.GONE);
                rly_gv_search.setVisibility(View.GONE);
                rly_lv_search.setVisibility(View.VISIBLE);
//                GetsearchStore(REFRESH);
//                searchListviewAdapter.notifyDataSetChanged();
                break;
            case R.id.rly_search://搜索
                Log.e("ssss", "搜索");
                SearchInfo searchinfo = new SearchInfo();
                //将搜索记录添加到数据库中
                searchinfo.setSearchname(et_search.getText().toString());
                dataHelper.SaveVoiceInfo(searchinfo);
                init_history_search();

                if (code == 0) {
                    Getsearchproduct(LOAD);//搜索商品
                    lly_search.setVisibility(View.GONE);
                    rly_gv_search.setVisibility(View.VISIBLE);
                    rly_lv_search.setVisibility(View.GONE);
                } else if (code == 1) {
                    Getsearchproduct(LOAD);//搜索门店
                    lly_search.setVisibility(View.GONE);
                    rly_gv_search.setVisibility(View.GONE);
                    rly_lv_search.setVisibility(View.VISIBLE);
                }
                break;
        }
    }


    //搜索商品
    private void Getsearchproduct(final int type) {
        CustomProgressDialog.createDialog(mActivity).show();
        SearchProductReq req = new SearchProductReq();
        String url = Const.COMMON_ADDRESS + req.urlString();

        req.setKeywords(et_search.getText().toString());
        if (type == LOAD || type == REFRESH) {
            page = 1;
        } else {
            page = searchproductList.size() / 20 + 1;
        }
        req.setPage(page + "");
        req.setPage_size("10");
        req.setSort("id");
        req.setOrder("asc");
        try {
            String source = req.getSecret();
            Rsa rsa = new Rsa();
            secret = rsa.encryptByPublic(source);
            Log.e("url", "source==" + source);
        } catch (Exception e) {
            e.printStackTrace();
        }

        params.put("secret", secret);
        Async_http_get.get(url, params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                CustomProgressDialog.Dismiss();
                gv_search_result.onRefreshComplete();

                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");
                if (errno.equals("000")) {
                    Log.e("url", "response==>" + response);
                    SearchProductResp resp = GsonImpl.get().toObject(response.toString(), SearchProductResp.class);
                    if (type == LOAD || type == REFRESH) {
                        searchproductList.clear();
                        searchproductList.addAll(resp.getResult().getData());
                    } else {
                        searchproductList.addAll(resp.getResult().getData());
                    }
                    if (searchproductList.size() % 10 > 0) {
                        gv_search_result.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
                    } else {
                        gv_search_result.setMode(PullToRefreshBase.Mode.BOTH);
                    }
                    searchGridviewAdapter.notifyDataSetChanged();
                } else if (errno.equals("003")) {
                    CommonUtil.showToast(mActivity, errmsg);
                    searchproductList.clear();
                    searchGridviewAdapter.notifyDataSetChanged();
                } else {
                    CommonUtil.showToast(mActivity, errmsg);

                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                CustomProgressDialog.Dismiss();
                CommonUtil.showToast(mActivity, "网络连接失败");

            }
        });
    }

    //商品Adapter
    private class SearchGridviewAdapter extends BaseAdapter {
        private List<SearchProductResp.ResultEntity.DataEntity> searchGridList;

        private SearchGridviewAdapter(List<SearchProductResp.ResultEntity.DataEntity> info) {
            if (info == null) {
                info = new ArrayList<>();
            }
            searchGridList = info;
        }

        @Override
        public int getCount() {
            return searchGridList.size();
        }

        @Override
        public SearchProductResp.ResultEntity.DataEntity getItem(int position) {
            return searchGridList.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup viewGroup) {
            ViewHolder vh = null;
            if (convertView == null) {
                convertView = LayoutInflater.from(mActivity).inflate(R.layout.search_gridview_list, null);
                vh = new ViewHolder();
                vh.img_search_product = (ImageView) convertView.findViewById(img_search_product);
                vh.tv_search_name = (TextView) convertView.findViewById(R.id.tv_search_name);
                vh.tv_search_describe = (TextView) convertView.findViewById(R.id.tv_search_describe);
                vh.tv_search_price = (TextView) convertView.findViewById(R.id.tv_search_price);
                vh.tv_search_original_price = (TextView) convertView.findViewById(R.id.tv_search_original_price);
                vh.tv_search_payment_number = (TextView) convertView.findViewById(R.id.tv_search_payment_number);

            } else {
                vh = (ViewHolder) convertView.getTag();
            }
            convertView.setTag(vh);
            convertView.setClickable(true);

            vh.tv_search_original_price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG); //中划线

            vh.tv_search_name.setText(getItem(position).getName());
            vh.tv_search_describe.setText(getItem(position).getDescription());
            vh.tv_search_payment_number.setText(getItem(position).getSales() + "人付款");

            vh.tv_search_price.setText("¥ " + getItem(position).getPrice());
            vh.tv_search_original_price.setText(getItem(position).getMarket_price());
            if (Double.parseDouble(getItem(position).getMarket_price()) == Double.parseDouble(getItem(position).getPrice())) {
                vh.tv_search_original_price.setVisibility(View.INVISIBLE);
            }
            ImageLoader.getInstance().displayImage(getItem(position).getList_thumb(), vh.img_search_product, displayImageOptions);

            convertView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mActivity, ProductDetails.class);
//                    intent.putExtra("is_Integral", getItem(position).getIs_integral());
                    intent.putExtra("id", getItem(position).getId());
                    Log.e("ssss", "商品ID==》" + getItem(position).getId());
                    startActivity(intent);
                }
            });
            return convertView;
        }

        private class ViewHolder {
            private ImageView img_search_product;
            private TextView tv_search_name, tv_search_describe, tv_search_price, tv_search_original_price, tv_search_payment_number;
        }
    }


//    //搜索门店
//    private void GetsearchStore(final int type) {
//        CustomProgressDialog.createDialog(mActivity).show();
//        SearchStoreReq req = new SearchStoreReq();
//        if (myApplication.getDataEntity() != null) {
//            req.setUuid(myApplication.getDataEntity().getUuid());
//        } else {
//            return;
//        }
//        if (type == LOAD || type == REFRESH) {
//            page = 1;
//        } else {
//            page = searchListviewlist.size() / 10 + 1;
//        }
//        req.setIndustry("");
//        req.setType("1");
//        req.setProduct_id("0");
//        if (sharedPreferencesUtil.getJingdu().equals("0") || sharedPreferencesUtil.getWeidu().equals("0")) {
//            req.setLat("0");
//            req.setLng("0");
//        } else {
//            req.setLat(sharedPreferencesUtil.getWeidu());
//            req.setLng(sharedPreferencesUtil.getJingdu());
//
//        }
//        req.setPage(page + "");
//
//
//        req.setPage_size("10");
//        RequestParams params = new RequestParams();
//
//        params.put("secret", req.getSecret());
//        Async_http_get.get(Const.COMMON_ADDRESS + req.urlString(), params, new JsonHttpResponseHandler() {
//            @Override
//            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
//                super.onSuccess(statusCode, headers, response);
//                CustomProgressDialog.Dismiss();
//                lv_search_result.onRefreshComplete();
//                Log.e("url", "json==" + response);
//                String errno = response.optString("errno");
//                String errmsg = response.optString("errmsg");
//                if (errno.equals("000")) {
//                    SearchStoreResp resp = GsonImpl.get().toObject(response.toString(), SearchStoreResp.class);
//                    if (type == LOAD || type == REFRESH) {
//                        searchListviewlist.clear();
//                        searchListviewlist.addAll(resp.getResult().getData());
//                    } else {
//                        searchListviewlist.addAll(resp.getResult().getData());
//                    }
//                    if (searchListviewlist.size() % 10 > 0) {
//                        lv_search_result.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
//                    } else {
//                        lv_search_result.setMode(PullToRefreshBase.Mode.BOTH);
//                    }
//                    searchListviewAdapter.notifyDataSetChanged();
//
//
//                }
//            }
//
//            @Override
//            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
//                super.onFailure(statusCode, headers, responseString, throwable);
//                CustomProgressDialog.Dismiss();
//                CommonUtil.showToast(mActivity, "网络连接失败");
//                lv_search_result.onRefreshComplete();
//            }
//        });
//
//    }
//
//    //门店Adapter
//    private class SearchListviewAdapter extends BaseAdapter {
//        private List<SearchStoreResp.ResultEntity.DataEntity> searchListList;
//
//        private SearchListviewAdapter(List<SearchStoreResp.ResultEntity.DataEntity> info) {
//            if (info == null) {
//                info = new ArrayList<>();
//            }
//            searchListList = info;
//        }
//
//        @Override
//        public int getCount() {
//            return searchListList.size();
//        }
//
//        @Override
//        public SearchStoreResp.ResultEntity.DataEntity getItem(int position) {
//            return searchListList.get(position);
//        }
//
//        @Override
//        public long getItemId(int position) {
//            return position;
//        }
//
//        @Override
//        public View getView(int position, View convertView, ViewGroup viewGroup) {
//            ViewHolder vh = null;
//            if (convertView == null) {
//                convertView = LayoutInflater.from(mActivity).inflate(R.layout.search_listview_list, null);
//                vh = new ViewHolder();
//                vh.img_search = (ImageView) convertView.findViewById(R.id.img_search);
//                vh.tv_search_name = (TextView) convertView.findViewById(R.id.tv_search_name);
//                vh.tv_search_address = (TextView) convertView.findViewById(R.id.tv_search_address);
//                vh.tv__search_distance = (TextView) convertView.findViewById(R.id.tv__search_distance);
//                vh.divide = (TextView) convertView.findViewById(R.id.divide1);
//                vh.lly_search_phone = (LinearLayout) convertView.findViewById(R.id.lly_search_phone);
//                vh.lly_search_gps = (LinearLayout) convertView.findViewById(R.id.lly_search_gps);
//                vh.lly_search_share = (LinearLayout) convertView.findViewById(R.id.lly_search_share);
//                vh.lly_search = (LinearLayout) convertView.findViewById(R.id.lly_search);
//
//            } else {
//                vh = (ViewHolder) convertView.getTag();
//            }
//            convertView.setTag(vh);
//            if (position > 0) {
//                vh.divide.setVisibility(View.VISIBLE);
//            }
//
//            //门店详情
//            vh.lly_search.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View view) {
//
//                }
//            });
//            //打电话
//            vh.lly_search_phone.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View view) {
//                    initPhonePopuWindow();
//                    pop_phone.setAnimationStyle(R.style.popupWindowAnimation);
//                    pop_phone.showAtLocation(mActivity.findViewById(R.id.lly_search_main), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
//                    pop_phone.update();
//                }
//            });
//            //导航
//            vh.lly_search_gps.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View view) {
//                    if (BaiduNaviManager.isNaviInited()) {
//                        routeplanToNavi(118.161024, 24.509077, BNRoutePlanNode.CoordinateType.GCJ02);
//
//                    }
//                }
//            });
//            //分享
//            vh.lly_search_share.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View view) {
//                    showShare();
//                }
//            });
//            return convertView;
//        }
//
//        private class ViewHolder {
//            private ImageView img_search;
//            private TextView tv_search_name, tv_search_address, tv__search_distance, divide;
//            private LinearLayout lly_search_phone, lly_search_gps, lly_search_share, lly_search;
//        }
//    }
//
//
//    //门店==》电话的popupwindow
//    private void initPhonePopuWindow() {
//
//        LayoutInflater inflater = LayoutInflater.from(mActivity);
//        View layout = inflater.inflate(R.layout.pop_phone, null);
//        lly_pop_phone = (LinearLayout) layout.findViewById(R.id.lly_pop_phone);
//        tv_pop_phone = (TextView) layout.findViewById(R.id.tv_pop_phone);
//        tv_pop_cancel = (TextView) layout.findViewById(R.id.tv_pop_cancel);
//        layout.invalidate();
//        pop_phone = new PopupWindow(layout, ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
//        pop_phone.setOnDismissListener(new PopupWindow.OnDismissListener() {
//            @Override
//            public void onDismiss() {
//
//            }
//        });
//        pop_phone.setBackgroundDrawable(new BitmapDrawable());
//        pop_phone.setOutsideTouchable(true);
//        pop_phone.setFocusable(true);
//
//        lly_pop_phone.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Intent intent = new Intent(Intent.ACTION_DIAL);
//                Uri data = Uri.parse("tel:" + tv_pop_phone.getText().toString());
//                intent.setData(data);
//                startActivity(intent);
//                pop_phone.dismiss();
//                pop_phone.setFocusable(false);
//            }
//        });
//
//        tv_pop_cancel.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                pop_phone.dismiss();
//                pop_phone.setFocusable(false);
//            }
//        });
//
//    }
//
//
//    public void routeplanToNavi(double jingdu, double weidu, BNRoutePlanNode.CoordinateType coType) {
//        BNRoutePlanNode sNode = null;
//        BNRoutePlanNode eNode = null;
//        Log.e("url", "目的地址:经度==" + jingdu + " 纬度==" + weidu);
//
//        switch (coType) {
//            case GCJ02: {
//                Log.e("ssss", "导航");
//                sNode = new BNRoutePlanNode(Double.parseDouble(sharedPreferencesUtil.getJingdu()), Double.parseDouble(sharedPreferencesUtil.getWeidu()), "目前地址", null, coType);
//
//                eNode = new BNRoutePlanNode(jingdu, weidu, "目的地", null, coType);
//                Log.e("url", "sNode==" + sNode + "   eNode==" + eNode);
//                Log.e("url", "当前地址:纬度==" + sharedPreferencesUtil.getJingdu() + " 经度==" + sharedPreferencesUtil.getWeidu());
//                Log.e("url", "目的地址:经度==" + jingdu + " 纬度==" + weidu);
//                break;
//            }
////            case WGS84: {
////                sNode = new BNRoutePlanNode(116.300821, 40.050969,
////                        "百度大厦", null, coType);
////                eNode = new BNRoutePlanNode(116.397491, 39.908749,
////                        "北京天安门", null, coType);
////                break;
////            }
////            case BD09_MC: {
////                sNode = new BNRoutePlanNode(12947471, 4846474,
////                        "百度大厦", null, coType);
////                eNode = new BNRoutePlanNode(12958160, 4825947,
////                        "北京天安门", null, coType);
////                break;
////            }
//            default:
//
//        }
//        if (sNode != null && eNode != null) {
//            List<BNRoutePlanNode> list = new ArrayList<BNRoutePlanNode>();
//            list.add(sNode);
//            list.add(eNode);
//            BaiduNaviManager.getInstance().launchNavigator(mActivity, list, 1, true, new DemoRoutePlanListener(sNode));
//        }
//    }
//
//    public class DemoRoutePlanListener implements BaiduNaviManager.RoutePlanListener {
//
//        private BNRoutePlanNode mBNRoutePlanNode = null;
//
//        public DemoRoutePlanListener(BNRoutePlanNode node) {
//            Log.e("url", "DemoRoutePlanListener");
//            mBNRoutePlanNode = node;
//            Log.e("url", "mBNRoutePlanNode==" + mBNRoutePlanNode);
//        }
//
//        @Override
//        public void onJumpToNavigator() {
//            Log.e("url", "onJumpToNavigator_BNDemoGuideActivity");
//            Intent intent = new Intent(mActivity, BNDemoGuideActivity.class);
//            Bundle bundle = new Bundle();
//            bundle.putSerializable(ROUTE_PLAN_NODE, (BNRoutePlanNode) mBNRoutePlanNode);
//            intent.putExtras(bundle);
//            startActivity(intent);
//        }
//
//        @Override
//        public void onRoutePlanFailed() {
//            // TODO Auto-generated method stub
//            Log.e("url", "onRoutePlanFailed");
//        }
//
//    }
//
//    private void initNavi() {
//
//        BNOuterTTSPlayerCallback ttsCallback = null;
//
//        BaiduNaviManager.getInstance().init(mActivity, mSDCardPath, APP_FOLDER_NAME,
//                new BaiduNaviManager.NaviInitListener() {
//                    @Override
//                    public void onAuthResult(int status, final String msg) {
//                        if (0 == status) {
//                            authinfo = "key校验成功!";
//                            Log.e("ssss", "key校验成功");
//                        } else {
//                            authinfo = "key校验失败, " + msg;
//                            Log.e("ssss", "key校验失败");
//                        }
//                        mActivity.runOnUiThread(new Runnable() {
//
//                            @Override
//                            public void run() {
////                                Toast.makeText(mActivity, authinfo, Toast.LENGTH_LONG).show();
//                                Log.e("ssss", "百度地图_authinfo===" + authinfo);
//                            }
//                        });
//
//                    }
//
//                    public void initSuccess() {
////                        Toast.makeText(mActivity, "百度导航引擎初始化成功", Toast.LENGTH_SHORT).show();
//                        Log.e("ssss", "百度导航引擎初始化成功");
//                    }
//
//                    public void initStart() {
////                        Toast.makeText(mActivity, "百度导航引擎初始化开始", Toast.LENGTH_SHORT).show();
//                        Log.e("ssss", "百度导航引擎初始化开始");
//                    }
//
//                    public void initFailed() {
////                        Toast.makeText(mActivity, "百度导航引擎初始化失败", Toast.LENGTH_SHORT).show();
//                        Log.e("ssss", "百度导航引擎初始化失败");
//                    }
//                }, null /*mTTSCallback*/);
//    }
//
//    private boolean initDirs() {
//        mSDCardPath = getSdcardDir();
//        if (mSDCardPath == null) {
//            return false;
//        }
//        File f = new File(mSDCardPath, APP_FOLDER_NAME);
//        if (!f.exists()) {
//            try {
//                f.mkdir();
//            } catch (Exception e) {
//                e.printStackTrace();
//                return false;
//            }
//        }
//        return true;
//    }
//
//    //分享
//    private void showShare() {
//        ShareSDK.initSDK(mActivity);
//        OnekeyShare oks = new OnekeyShare();
//        //关闭sso授权
//        oks.disableSSOWhenAuthorize();
//
//        // title标题，印象笔记、邮箱、信息、微信、人人网和QQ空间等使用
//        oks.setTitle("标题");
//        // titleUrl是标题的网络链接，QQ和QQ空间等使用
//        oks.setTitleUrl("http://sharesdk.cn");
//        // text是分享文本，所有平台都需要这个字段
//        oks.setText("我是分享文本");
//        // imagePath是图片的本地路径，Linked-In以外的平台都支持此参数
//        //oks.setImagePath("/sdcard/test.jpg");//确保SDcard下面存在此张图片
//        // url仅在微信（包括好友和朋友圈）中使用
//        oks.setUrl("http://sharesdk.cn");
//        // comment是我对这条分享的评论，仅在人人网和QQ空间使用
//        oks.setComment("我是测试评论文本");
//        // site是分享此内容的网站名称，仅在QQ空间使用
//        oks.setSite(getString(R.string.app_name));
//        // siteUrl是分享此内容的网站地址，仅在QQ空间使用
//        oks.setSiteUrl("http://sharesdk.cn");
//
//        // 启动分享GUI
//        oks.show(mActivity);
//    }
}
